#ifndef ZG_MUTEX_H
#define ZG_MUTEX_H

#include "pthread.h"
#include "errno.h"
#define MAX_SIZE 2048
namespace zg_util{
    class Mutex{
    public:
        Mutex();
        ~Mutex();
        void lock();
        bool tryLock();
        void unlock();
    private:
        Mutex(const Mutex&);
        Mutex& operator = (const Mutex&);
        pthread_mutex_t _mutex;
    };
    inline void Mutex::lock()
    {
        pthread_mutex_lock(&_mutex);
    }


    inline bool Mutex::tryLock()
    {
        int rc = pthread_mutex_trylock(&_mutex);
        if (rc == 0)
            return true;
        else if (rc == EBUSY)
            return false;

    }


    inline void Mutex::unlock()
    {
       pthread_mutex_unlock(&_mutex);
    }
}

#endif
